﻿@{
    ViewData["Title"] = "Easy";
}

<script>
    function enable(btn, value) {
        var _this = $(btn);
        var isEnable = _this.hasClass("btn-success");
        var action = "Enable";
        if (isEnable) {
            action = "Disable";
        }
        else {
            action = "Enable";
        }

        $.ajax({
            url: "/Easy/" + action,
            type: "Post",
            dataType: "json",
            data: {
                name: value,
            },
            success: function (result) {
                if (result.success) {
                    if (isEnable) {
                        _this.removeClass("btn-success");
                        _this.addClass("btn-default")
                    }
                    else {
                        _this.removeClass("btn-default");
                        _this.addClass("btn-success")
                    }
                }
                else {
                    alert(result.massage);
                }
            }
        })
    }

    function deletePath(btn, value) {
        if (confirm("警告：" + "\n" + "\n" + "将要删除共享[" + value + "]，" + "\n" + "且不可恢复！" + "\n" + "\n" + "是否继续？")) {
            var _this = $(btn);
            $.ajax({
                url: "/Easy/Delete",
                type: "Post",
                dataType: "json",
                data: {
                    name: value,
                },
                success: function (result) {
                    if (result.success) {
                        window.location.reload();
                    }
                    else {
                        alert(result.massage);
                    }
                }
            })
        }
    }
</script>

@foreach (var configNode in @Model.ConfigNodeList)
{
    var buttonClass = @configNode.IsEnable ? "btn btn-success btn-xs" : "btn btn-default btn-xs";
<div class="panel panel-default" style="margin-top:20px">
    <div class="panel-heading">
        <button type="button" class="@buttonClass" onclick="enable(this, '@configNode.Name');">启用</button>
        <strong>@configNode.Name</strong>
        <div class="btn-group btn-group-xs" style="float:right">
            <a class="btn btn-warning" href="/Easy/Edit?name=@configNode.Name">修改</a>
            <button type="button" class="btn btn-danger" onclick="deletePath(this, '@configNode.Name');">删除</button>
        </div>
    </div>

    <div class="panel-body">
        <ul class="list-unstyled">
            <li><strong>目录：</strong>@configNode.Path</li>
            @{
                var userInfo = string.IsNullOrWhiteSpace(@configNode.User) ? "无" : $"{@configNode.User}（需要密码）";
            }
            <li><strong>用户：</strong>@userInfo</li>
            @{
                var publicInfo = @configNode.EveryOne ? "任何人（无需密码）" : "否";
            }
            <li><strong>只读：</strong>@(configNode.ReadOnly ? "是" : "否")</li>
            <li><strong>公开：</strong>@publicInfo</li>
        </ul>
    </div>
</div>
}

<a class="btn btn-primary" href="/Easy/New">新建共享</a>